package com.kalaqia.image.library;

import android.content.Context;
import android.support.annotation.NonNull;
import android.widget.ImageView;

/**
 * function:
 * project:kalaqia
 * describe:
 * created owner:kalaqia 421407393@qq.com
 * created date:2017/8/4 14:15
 */
//<editor-fold desc="version update log">
// update owner:kalaqia  421407393@qq.com
// update datetime:2017/8/4 14:15
// update remark:
//</editor-fold>
public class ImageLoaderOptions {

    private Object context;
    private Object url;
    private Object container;
    private int errorResId;
    private int holderDrawable;
    private int diskCacheStrategy;
    private int imageType;
    private boolean isCrossFade;
    private boolean isSkipMemoryCache;
    private ImageLoadListener imageLoadListener;

    private ImageLoaderOptions(Builder builder) {
        this.url = builder.url;
        this.container = builder.container;
        this.errorResId = builder.errorResId;
        this.diskCacheStrategy = builder.diskCacheStrategy;
        this.imageType = builder.imageType;
        this.holderDrawable = builder.holderDrawable;
        this.isCrossFade = builder.isCrossFade;
        this.context = builder.context;
        this.isSkipMemoryCache = builder.isSkipMemoryCache;
        this.imageLoadListener = builder.imageLoadListener;
    }

    public Object getUrl() {
        return url;
    }

    public Object getContainer() {
        return container;
    }

    public ImageLoadListener getImageLoadListener() {
        return imageLoadListener;
    }

    public int getErrorResId() {
        return errorResId;
    }

    public int getHolderDrawable() {
        return holderDrawable;
    }

    public int getDiskCacheStrategy() {
        return diskCacheStrategy;
    }

    public int getImageType() {
        return imageType;
    }

    public boolean isCrossFade() {
        return isCrossFade;
    }

    public boolean isListenReturn() {
        return imageLoadListener != null;
    }

    public boolean isSkipMemoryCache() {
        return isSkipMemoryCache;
    }

    public Object getContext() {
        if (context != null) return context;
        if (container != null && container instanceof ImageView) return this.container;
        return null;
    }

    public boolean isRequestOptionsEmpty() {
        return (getHolderDrawable() >= 0 || getErrorResId() >= 0 || getDiskCacheStrategy() != ImageDiskCacheStrategy.DEFAULT);
    }

    public final static class Builder {
        private Object url;
        private Object container;
        private Object context;
        private int errorResId;
        private int holderDrawable;
        private int diskCacheStrategy = ImageDiskCacheStrategy.DEFAULT;
        private int imageType = ImageType.TYPE_DRAWABLE;
        private boolean isCrossFade = false;
        private boolean isSkipMemoryCache = false;
        private ImageLoadListener imageLoadListener;

        public Builder(@NonNull Object context, @NonNull Object url) {
            this.context = context;
            this.url = url;
        }

        public Builder setContainer(Object container) {
            this.container = container;
            return this;
        }

        public Builder setImageLoadListener(ImageLoadListener imageLoadListener) {
            this.imageLoadListener = imageLoadListener;
            return this;
        }

        public Builder setErrorResId(int errorResId) {
            this.errorResId = errorResId;
            return this;
        }

        public Builder setContext(Context context) {
            this.context = context;
            return this;
        }

        public Builder setSkipMemoryCache(boolean skipMemoryCache) {
            isSkipMemoryCache = skipMemoryCache;
            return this;
        }

        public Builder setCrossFade(boolean crossFade) {
            isCrossFade = crossFade;
            return this;
        }

        public Builder setHolderDrawable(int holderDrawable) {
            this.holderDrawable = holderDrawable;
            return this;
        }

        public Builder setDiskCacheStrategy(int diskCacheStrategy) {
            this.diskCacheStrategy = diskCacheStrategy;
            return this;
        }

        public Builder setUrl(Object url) {
            this.url = url;
            return this;
        }

        public Builder setImageType(int imageType) {
            this.imageType = imageType;
            return this;
        }

        public ImageLoaderOptions build() {
            return new ImageLoaderOptions(this);
        }

    }

}
